import re

str1 = """TCP Student  192.168.189.167:32806 Teacher  137.78.5.128:65247, idle 0:00:00, bytes 74, flags UIO 
TCP Student  192.168.189.167:80 Teacher  137.78.5.128:65233, idle 0:00:03, bytes 334516, flags UIO """

list1 = str1.split('\n')

asa_dict = {}

for x in list1:
    result = re.match('.*\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5}).*\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5}).*bytes\s+(\d+).*flags\s+(\w*)',x).groups()
    asa_key = result[0],result[1],result[2],result[3]
    asa_value = result[4],result[5]
    asa_dict[asa_key] = asa_value

print('打印字典\n')
print(asa_dict)

print('\n\n格式化打印输出\n')

for key,value in asa_dict.items():
    print('{0:>10} : {1:<20} | {2:>10} : {3:<10} | {4:>10} : {5:<20} | {6:>10} : {7:<10} |'.format('src',key[0],'src_p',key[1],'dst',key[2],'dst_p',key[3]))
    print('{0:>10} : {1:<20} | {2:>10} : {3:<10} |'.format('bytes',value[0],'flags',value[1]))
    print('=' * 125)


'''
打印字典

{('192.168.189.167', '32806', '137.78.5.128', '65247'): ('74', 'UIO'), ('192.168.189.167', '80', '137.78.5.128', '65233'): ('334516', 'UIO')}


格式化打印输出

       src : 192.168.189.167      |      src_p : 32806      |        dst : 137.78.5.128         |      dst_p : 65247      |
     bytes : 74                   |      flags : UIO        |
=============================================================================================================================
       src : 192.168.189.167      |      src_p : 80         |        dst : 137.78.5.128         |      dst_p : 65233      |
     bytes : 334516               |      flags : UIO        |
=============================================================================================================================
'''